import { webGet, webPost } from './web-request.js';
export const apiPrx = "/api";

export interface UserContext {
	id: number;
	name: string;
	username: string;
	fullname: string;
	storeIds: string[];
}

export async function login(username: string, pwd: string) {
	const r = await webPost('/api/login', { body: { username, pwd } });
	return r.result;
}

export async function logoff() {
	const r = await webPost('/api/logoff', { body: { logoff: true } });
	return r;
}

export async function getUserContext(): Promise<UserContext | null> {
	const ucResult = await webGet(`${apiPrx}/user-context`);
	if (ucResult && ucResult.success) {
		return ucResult;
	}
	return null;
}
